package com.lj.infoisland.common.enums;

/*
 * @description 用户角色枚举
 * @author 龙洁
 * @create 2024-12-25 上午10:01
 */
public enum UserRole {

    // user: 普通用户 admin: 管理员
    USER("user", "普通用户"),
    ADMIN("admin", "管理员");

    private final String code;
    private final String description;

    UserRole(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据code获取description
     *
     * @param code code
     * @return description
     */
    public static String code2Description(String code) {
        for (UserRole userRole : UserRole.values()) {
            if (userRole.getCode().equals(code)) {
                return userRole.getDescription();
            }
        }
        return null;
    }
}
